﻿// *************************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2018. All rights reserved.
//  
// Web: http://www.scichart.com
//   Support: support@scichart.com
//   Sales:   sales@scichart.com
// 
// CandlestickChartExampleView.xaml.cs is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use. 
// 
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied. 
// *************************************************************************************
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using SciChart.Charting.Model.DataSeries;
using SciChart.Charting.Visuals.RenderableSeries.Animations;
using SciChart.Examples.ExternalDependencies.Common;
using SciChart.Examples.ExternalDependencies.Data;

namespace SciChart.Examples.Examples.CreateSimpleChart
{
    public partial class CandlestickChartExampleView : UserControl
    {
        public CandlestickChartExampleView()
        {
            InitializeComponent();
        }

        private void CandlestickChartExampleView_OnLoaded(object sender, RoutedEventArgs e)
        {
            // Create a dataset of type x=DateTime, y=Double
            var dataSeries = new OhlcDataSeries<DateTime, double>();                     

            // Prices are in the format Time, Open, High, Low, Close (all IList)
            var prices = DataManager.Instance.GetPriceData(Instrument.Indu.Value, TimeFrame.Daily);            
            
            // Append data to series. SciChart automatically redraws
            dataSeries.Append(
                prices.TimeData,
                prices.OpenData,
                prices.HighData,
                prices.LowData,
                prices.CloseData);

            sciChart.RenderableSeries[0].DataSeries = dataSeries;

            // Zoom Extents - necessary as we have AutoRange=False
            sciChart.ZoomExtents();
        }
    }
}
